$(function() {
	var getArticleMenu = function() {
		var $article = $('article');
		var hArray = ['h2', 'h3'];
		var $hs = $article.find(hArray.toString());
		var meun = [];

		$hs.each(function(index) {
			var meunitem = {
				"title": "root",
				"$el": null,
				"child": []
			}
			var tgname = (this.tagName).toLowerCase();
			meunitem.title = $(this).text();
			meunitem.$el = $(this);

			if(tgname == hArray[0]) {
				meun.push(meunitem);
			}
			if(tgname == hArray[1]) {
				meun[(meun.length - 1)]['child'].push(meunitem)
			}
		});
		return meun;
	};
	var meun = getArticleMenu();
	var getUlStr = function(lis) {
		return lis == '' ? '' : ('<ul>' + lis + '</ul>');
	};
	//	var getUlLi = function(c) {
	//		var listr = '',
	//			_arguments = arguments,
	//			$el = null;
	//		c.forEach(function(item, index, array) {
	//			$el = item.$el;
	//			if(item.child.length > 0) {
	//				listr += '<li class="leve'+ $el.get(0).tagName +'">' + item.title + '</li>';
	//				listr += _arguments.callee(item.child);
	//			} else {
	//				listr += '<li class="leve'+ $el.get(0).tagName +'">' + item.title + '</li>';
	//			}
	//		});
	//		return listr;
	//	};
	var getRandomNum = function(max) {
		var a = new Array();
		for(var i = 0; i < max; i++) {
			a.push(i)
		};
		return function() {
			return a.pop();
		}
	}(100);

	var getUlLi = function(c) {
		var listr = '',
			_arguments = arguments,
			$el = null,
			tgid = '';
		c.forEach(function(item, index, array) {
			$el = item.$el;
			tgid = getRandomNum();
			$el.attr('id', tgid)
			if(item.child.length > 0) {
				var clis = _arguments.callee(item.child);
				listr += '<li><a title="'+ item.title +'" href="#' + tgid + '">' + item.title + '</a>' + getUlStr(clis) + '</li>';
			} else {
				listr += '<li><a title="'+ item.title +'" href="#' + tgid + '">' + item.title + '</a></li>';
			}
		});
		return listr;
	};
	var rzol = '<ol>' + getUlLi(meun) + '</ol>';
	console.info(rzol);
	var $catalogs = $('#catalog-list').html(rzol),
		$lis = $catalogs.find('>ol>li'),
		liheight = [],
		maxh = '108px';
	$lis.each(function(index) {
		liheight.push($(this).height());
	});
	maxh = Math.max.apply(this, liheight) + 'px';
	$lis.css({
		'height': 0,
		opacity: '0'
	}).animate({
		opacity: 1,
		height: maxh
	});
})